#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

struct Node
{
    char *mozhou, *gongneng;
};

vector<Node> mz[ 81 ], gn[ 21 ];

void init( )
{
    int i, j;
    Node p1, p2;
    char data[ 150 ], data2[ 150 ];
    while ( gets( data ) && strcmp( data, "@END@" ) != 0 )
    {
        for ( i = 1; data[ i ] != ']'; i++ )
            data2[ i - 1 ] = data[ i ];
        data2[ i - 1 ] = '\0';
        p1.gongneng = new char[ strlen( data ) - i - 1 ];
        strcpy( p1.gongneng, data + i + 2 );
        p2.mozhou = new char[ strlen( data2 ) + 1 ];
        strcpy( p2.mozhou, data2 );
        p1.mozhou = p2.mozhou;
        p2.gongneng = p1.gongneng;
        mz[ strlen( data ) - i - 2 ].push_back( p1 );
        gn[ strlen( data2 ) ].push_back( p2 );
    }
}

void work( )
{
    char data[ 150 ], data2[ 150 ];
    int i, j, t, c, len;
    vector<Node>::iterator ii;
    scanf("%d", &c);
    gets( data );
    while ( c-- )
    {
        gets( data );
        if ( data[ 0 ] == '[' )
        {
            for ( i = 1; i < strlen( data ) - 1; i++ )
                data2[ i - 1 ] = data[ i ];
            data2[ i - 1 ] = '\0';
            len = strlen( data2 );
            for ( ii = gn[ len ].begin( ); ii != gn[ len ].end( ); ii++ )
                if ( strcmp( ii->mozhou, data2 ) == 0 )
                    break;
            if ( ii == gn[ len ].end( ) )
                puts("what?");
            else
                puts( ii->gongneng );
        }
        else
        {
            len = strlen( data );
            for ( ii = mz[ len ].begin( ); ii != mz[ len ].end( ); ii++ )
                if ( strcmp( ii->gongneng, data ) == 0 )
                    break;
            if ( ii == mz[ len ].end( ) )
                puts("what?");
            else
                puts( ii->mozhou );
        }
    }
}


int main( )
{
    init( );
    work( );
    return 0;
}
